local hx__wajie = fk.CreateSkill {
  name = "hx__wajie",
  tags = { Skill.Limited },
}


hx__wajie:addEffect(fk.RoundStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__wajie.name) and player:usedSkillTimes(hx__wajie.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = hx__wajie.name,
      prompt = "你可以失去1点体力并减少1点体力上限，令所有其他角色于本轮内获得减益！",
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, hx__wajie.name)
    room:changeMaxHp(player, -1)
    for _, p in ipairs(room:getOtherPlayers(player)) do
      room:setPlayerMark(p, "@@hx__wajie-round", 1)
    end
  end
})

hx__wajie:addEffect(fk.EventPhaseStart, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target ~= player and target.phase == Player.Finish and target:getMark("@@hx__wajie-round") > 0
    and player:hasSkill(hx__wajie.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.room:doAnimate("InvokeSkill", {
      name = "hx__wajie",
      player = player.id,
      skill_type = "offensive",
    })
    player:broadcastSkillInvoke(hx__wajie.name)
    local choice = room:askToChoice(target, {
      skill_name = hx__wajie.name,
      prompt = "请选择一张牌",
      choices = {"#hx__wajie-discard","#hx__wajie-maxhp"},
    })
    if choice == "#hx__wajie-discard" then
      room:loseHp(target, 1, hx__wajie.name)
      room:askToDiscard(target, {
        min_num = 2,
        max_num = 2,
        include_equip = true,
        skill_name = hx__wajie.name,
        cancelable = false,
      })
    else
      room:changeMaxHp(target, -1)
    end
  end
})


return hx__wajie
